import request from '../../utils/request'


/**
 * 查询外汇信息
 * @param payman
 * @param beginAmt
 * @param endAmt
 * @param payaccount
 * @param beginTime
 * @param endTime
 * @param status
 * @param userIds
 * @param page
 * @returns {Promise.<void>}
 */
export async function getForexList({payman, beginAmt, endAmt, payaccount, beginTime, endTime,contractno, status, userIds, nameOrCode, page}) {
    userIds = 1;
    if(status == 0){
        status = null;
    }
    return request(apiPath.mc + "/api/forexs", {
        method: 'get',
        data: {
            payman,
            beginAmt,
            endAmt,
            payaccount,
            contractno,
            beginTime,
            endTime,
            status,
            userIds,
            nameOrCode,
            page: page.page,
            size: page.size
        }
    });
}


/**
 * 获取外汇详情
 * @param id
 * @returns {Promise.<void>}
 */
export async function getForexById({id}) {
    return request(apiPath.mc + "/api/forex/" + id, {
        method: 'get'
    });
}


/**
 * 获取付汇人
 */
export async function queryPaymen() {
    return request(apiPath.mc+"/api/payman",{
        method:'get'
    });
}

/**
 * 增加外汇
 * @param payaccount
 * @param payman
 * @param rectime
 * @param recamount
 * @param recamountunit
 * @param recaccount
 * @param settlement
 * @param memo
 * @returns {Promise.<void>}
 */
export async function addForex({payaccount, payman, rectime, recamount, recamountunit, recaccount, settlement, memo, country, recaccountName}) {

    return request(apiPath.mc + "/api/forex", {
        method: 'post',
        data: {payaccount, payman, rectime, recamount, recamountunit, recaccount, settlement, memo, country, recaccountName}
    });
}

export async function updateForex({id, exchangeurl}) {
    
        return request(apiPath.mc + "/api/forex", {
            method: 'put',
            data: {id, exchangeurl}
        });
    }

/**
 * 结汇
 * @param id
 * @param exchangetime
 * @param bankexchangeamount
 * @param bankexchangerate
 * @param cstexchangeamount
 * @param cstexchangerate
 * @param exchangefilename
 * @param exchangeurl
 * @returns {Promise.<void>}
 */
export async function exchange({id, exchangetime, bankexchangeamount, bankexchangerate, cstexchangeamount, cstexchangerate, exchangefilename, exchangeurl}) {

    /**
     * TODO
     * 文件上传
     * @type {string}
     */
    exchangefilename =exchangeurl.substring(exchangeurl.lastIndexOf('/')+1,exchangeurl.length);
    // exchangeurl = "tt/com";


    return request(apiPath.mc + "/api/forex/" + id + "/exchange", {
        method: 'put',
        data: { exchangetime, bankexchangeamount, bankexchangerate, cstexchangeamount, cstexchangerate, exchangefilename, exchangeurl}
    });
}


/**
 * 删除外汇
 * @param id
 * @param userId
 * @returns {Promise.<void>}
 */
export async function deleteForex({id}) {
    return request(apiPath.mc + "/api/forex/" + id, {
        method: 'delete'
    });
}


/**
 * 外汇审核
 * @param forexId
 * @param approvalresult
 * @param approvalmemo
 * @param businesstype
 * @param entityid
 * @returns {Promise.<void>}
 */
export async function approvalForex({forexId, approvalresult, approvalmemo, businesstype, entityid}) {
    businesstype = "forex";
    return request(apiPath.mc + "/api/forex/" + forexId + "/approval" , {
        method: 'post',
        data: {approvalresult, approvalmemo, businesstype, entityid}
    });


}
export async function splitForex({forexId,amount}) {
    return request(apiPath.mc+"/api/forex/"+forexId+"/splitForex",{
        method:'post',
        data:{amount}
    });

}


export async function rollbackForex({ forexId }) {
    return request(apiPath.mc+"/api/forex/rollback",{
        method:'post',
        data: { forexId }
    });

}